<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */

$this->headTitle($this->TRANSLATOR->translator('install_step1_page_title') . ' - ' . $this->TRANSLATOR->translator('common_admin_title'));
?>
<div id="desc">
	<div class="body">
		<div id="messages"></div>
		<div class="content">
			<div class="box header">
				<div class="head"><div></div></div>
				<h2>
					<?php echo $this->TRANSLATOR->translator('install_step1_title'); ?>
				</h2>
				<div class="desc">
					<div class="content">
						<form action="<?php echo $this->url('core_install_step1'); ?>" method="post" id="coreInstallStep1">
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_server_static'); ?></label>
								<input type="text" class="text w_20" name="configs[server][static]" id="config_server_static" value="<?php if (isset($this->configs->server->static)) : ?><?php echo $this->configs->server->static; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['server_static'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['server_static']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_server_resource'); ?></label>
								<input type="text" class="text w_20" name="configs[server][resource]" id="config_server_resource" value="<?php if (isset($this->configs->server->resource)) : ?><?php echo $this->configs->server->resource; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['server_resource'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['server_resource']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_name'); ?></label>
								<input type="text" class="text w_20" name="configs[web][name]" id="config_web_name" value="<?php if (isset($this->configs->web->name)) : ?><?php echo $this->configs->web->name; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['web_name'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['web_name']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_url'); ?></label>
								<input type="text" class="text w_20" name="configs[web][url]"  id="config_web_url" value="<?php if (isset($this->configs->web->url)) : ?><?php echo $this->configs->web->url; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['web_url'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['web_url']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_template'); ?></label>
								<input type="text" class="text w_20" name="configs[web][template]"  id="config_web_template" value="<?php if (isset($this->configs->web->template)) : ?><?php echo $this->configs->web->template; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['web_template'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['web_template']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_skin'); ?></label>
								<input type="text" class="text w_20" name="configs[web][skin]"  id="config_web_skin" value="<?php if (isset($this->configs->web->skin)) : ?><?php echo $this->configs->web->skin; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['web_skin'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['web_skin']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_language'); ?></label>
								<select name="configs[web][language]"  id="config_web_language">
									<?php if (isset($this->locales) && $this->locales) : ?>
									<?php foreach ($this->locales as $code => $locale) : ?>
									<option value="<?php echo $locale['code']; ?>"<?php if ($this->APP_LANG == $locale['code']): ?> selected="selected"<?php endif; ?>><?php echo $locale['localName']; ?> (<?php echo $locale['englishName']; ?>)</option>
									<?php endforeach; ?>
									<?php endif; ?>
								</select>
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['web_language'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['web_language']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_admin_url_prefix'); ?></label>
								<input type="text" class="text w_20" name="configs[web][admin][url_prefix]"  id="config_web_admin_url_prefix" value="<?php if (isset($this->configs->web->admin->url_prefix)) : ?><?php echo $this->configs->web->admin->url_prefix; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['web_admin_url_prefix'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['web_admin_url_prefix']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_admin_template'); ?></label>
								<input type="text" class="text w_20" name="configs[web][admin][template]"  id="config_web_admin_template" value="<?php if (isset($this->configs->web->admin->template)) : ?><?php echo $this->configs->web->admin->template; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_rewrite'); ?></label>
								<select id="config_web_rewrite" name="configs[web][rewrite]">
<!--									<option value="false"<?php if (isset($this->configs->web->rewrite) && $this->configs->web->rewrite == 'false') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_web_rewrite_false'); ?></option>-->
									<option value="true"<?php if (isset($this->configs->web->rewrite) && $this->configs->web->rewrite == 'true') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_web_rewrite_true'); ?></option>
								</select>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_meta_keyword'); ?></label>
								<textarea cols="100" rows="5" name="configs[web][meta][keyword]"><?php if (isset($this->configs->web->meta->keyword)) : ?><?php echo $this->configs->web->meta->keyword; ?><?php endif; ?></textarea>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_meta_description'); ?></label>
								<textarea cols="100" rows="5" name="configs[web][meta][description]"><?php if (isset($this->configs->web->meta->description)) : ?><?php echo $this->configs->web->meta->description; ?><?php endif; ?></textarea>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_offline_enable'); ?></label>
								<select id="config_web_offline_enable" name="configs[web][offline][enable]">
									<option value="false"<?php if (isset($this->configs->web->offline->enable) && $this->configs->web->offline->enable == 'false') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_web_offline_enable_false'); ?></option>
									<option value="true"<?php if (isset($this->configs->web->offline->enable) && $this->configs->web->offline->enable == 'true') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_web_offline_enable_true'); ?></option>
								</select>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_web_offline_message'); ?></label>
								<input type="text" class="text w_30" name="configs[web][offline][message]" id="config_web_offline_message" value="<?php if (isset($this->configs->web->offline->message)) : ?><?php echo $this->configs->web->offline->message; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							
							<!-- Database -->
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_host'); ?></label>
								<input type="text" class="text w_20" name="configs[db][host]" id="config_db_host" value="<?php if (isset($this->configs->db->host)) : ?><?php echo $this->configs->db->host; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_port'); ?></label>
								<input type="text" class="text w_20" name="configs[db][port]" id="config_db_port" value="<?php if (isset($this->configs->db->port)) : ?><?php echo $this->configs->db->port; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_username'); ?></label>
								<input type="text" class="text w_20" name="configs[db][username]" id="config_db_username" value="<?php if (isset($this->configs->db->username)) : ?><?php echo $this->configs->db->username; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_password'); ?></label>
								<input type="password" class="text w_20" name="configs[db][password]" id="config_db_password" value="<?php if (isset($this->configs->db->password)) : ?><?php echo $this->configs->db->password; ?><?php endif; ?>" />
								<a href="javascript: void(0);" id="g_a_db_connection" title="<?php echo $this->TRANSLATOR->translator('website_config_db_test_connection'); ?>"><?php echo $this->TRANSLATOR->translator('website_config_db_test_connection'); ?></a>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_name'); ?></label>
								<select id="config_db_name" name="configs[db][name]"></select>
								<input disabled="disabled" style="display: none;" type="text" class="text w_20" name="configs[db][name]" id="config_db_name_text" value="<?php if (isset($this->configs->db->name)) : ?><?php echo $this->configs->db->name; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['db_name'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['db_name']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_table_prefix'); ?></label>
								<input type="text" class="text w_20" name="configs[db][table_prefix]" id="config_db_table_prefix" value="<?php if (isset($this->configs->db->table_prefix)) : ?><?php echo $this->configs->db->table_prefix; ?><?php endif; ?>" />
								<?php if (isset($this->errorMessages) && isset($this->errorMessages['db_table_prefix'])) : ?>
								<span class="g_a_error"><?php echo $this->TRANSLATOR->translator($this->errorMessages['db_table_prefix']); ?></span>
								<?php endif; ?>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_db_encoding'); ?></label>
								<input type="text" class="text w_20" name="configs[db][encoding]" id="config_db_encoding" value="<?php if (isset($this->configs->db->encoding)) : ?><?php echo $this->configs->db->encoding; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<!-- / Database -->
							
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_cache_enable'); ?></label>
								<select id="config_cache_enable" name="configs[cache][enable]">
									<option value="false"<?php if (isset($this->configs->cache->enable) && $this->configs->cache->enable == 'false') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_cache_enable_false'); ?></option>
									<option value="true"<?php if (isset($this->configs->cache->enable) && $this->configs->cache->enable == 'true') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_cache_enable_true'); ?></option>
								</select>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_cache_timeout'); ?></label>
								<input type="text" class="text w_20" name="configs[cache][timeout]" id="config_cache_timeout" value="<?php if (isset($this->configs->cache->timeout)) : ?><?php echo $this->configs->cache->timeout; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_cache_compress'); ?></label>
								<select id="config_cache_enable" name="configs[cache][compress]">
									<option value="false"<?php if (isset($this->configs->cache->compress) && $this->configs->cache->compress == 'false') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_cache_compress_false'); ?></option>
									<option value="true"<?php if (isset($this->configs->cache->compress) && $this->configs->cache->compress == 'true') : ?> selected<?php endif; ?>><?php echo $this->TRANSLATOR->translator('website_config_cache_compress_true'); ?></option>
								</select>
								<br>
							</p>
							<p class="small">&nbsp;</p>
							
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_session_lifetime'); ?></label>
								<input type="text" class="text w_20" name="configs[session][lifetime]" id="config_session_lifetime" value="<?php if (isset($this->configs->session->lifetime)) : ?><?php echo $this->configs->session->lifetime; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							<p>
								<label for="simple_input"><?php echo $this->TRANSLATOR->translator('website_config_session_inactive'); ?></label>
								<input type="text" class="text w_20" name="configs[session][inactive]" id="config_session_inactive" value="<?php if (isset($this->configs->session->inactive)) : ?><?php echo $this->configs->session->inactive; ?><?php endif; ?>" />
								<br>
							</p>
							<p class="small">&nbsp;</p>
							
							<p class="last buttons_demo">
								<a class="button form_submit green" href="<?php echo $this->url('core_website_config'); ?>"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('common_submit_button'); ?></span></a>
								<a class="button red" href="javascript: history.go(-1);"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_back_button'); ?></span></a>
							</p>
						</form>
					</div>
					<div class="clear"></div>
				</div>
				<div class="bottom"><div></div></div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$('#g_a_db_connection').bind('click', function() {
		/**
		 * Show g_a_ajax_loading element
		 */
		$('#g_a_ajax_loading').show();
		$.ajaxq('db_testconnection', {
			type: 'post',
			url: '<?php echo $this->url('core_install_step1'); ?>',
			data: { act: 'testdbconn', host: $('#config_db_host').val(), port: $('#config_db_port').val(), username: $('#config_db_username').val(), password: $('#config_db_password').val() },
			success: function(response) {
				response = $.evalJSON(response);
				if (response.result == 'RESULT_OK') {
					var databases = response.databases;
					if (databases.length > 0) {
						for (var i in databases) {
							var option = $('<option/>');
							<?php if (isset($this->configs->db->name)) : ?>
							if (databases[i] == '<?php echo $this->configs->db->name; ?>') {
								$(option).attr('selected', 'selected');
							}
							<?php endif; ?>

							$(option).val(databases[i]).html(databases[i]).appendTo($('#config_db_name'));
						}
						$('#config_db_name').removeAttr('disabled').show();
						$('#config_db_name_text').attr('disabled', 'disabled').hide();
					} else {
						$('#config_db_name').attr('disabled', 'disabled').hide();
						$('#config_db_name_text').removeAttr('disabled').show();
					}
					var message = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('website_config_db_test_connection_success')); ?>';
					Gio.Message.success(message);
				} else {
					var message = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('website_config_db_test_connection_error')); ?>';
					Gio.Message.error(message);
				}
				
				/**
				 * Hide g_a_ajax_loading element
				 */
				$('#g_a_ajax_loading').hide();
			}
		});
	});
});
</script>